package de.dih.findih;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class EintragsAdapter extends SimpleAdapter {
	private ArrayList<View> rows;
	private ArrayList<HashMap<String, Object>> data;

	public EintragsAdapter(Context context, ArrayList<HashMap<String, Object>> data, int resource, String[] from, int[] to) {
		super(context, data, resource, from, to);
		this.data = data;
		rows = new ArrayList<View>();
	}

	public View getRow(int position) throws Exception {
		try {
			return rows.get(position);
		} catch (Exception e) {
			Log.e("SQLITE", "Array out of bounds: Adapter does not have that many rows");
			throw new Exception();
		}
	}

	public int getRowCount() {
		return rows.size();

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = super.getView(position, convertView, parent);
		TextView tvBetrag = (TextView) rowView.findViewById(R.id.betrag);
		if (data.get(position).get("art").toString().equals("Ausgabe")) {
			tvBetrag.setTextColor(Color.RED);
		} else {
			tvBetrag.setTextColor(Color.GREEN);
		}
		rows.add(rowView);
		return rowView;
	}

}
